/*
 * @Description:
 * @Autor: Bingo
 * @Date: 2022-12-12 09:48:36
 * @LastEditors: Bingo
 * @LastEditTime: 2024-09-02 08:58:54
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// jsx插件
import vueJsx from "@vitejs/plugin-vue-jsx";
// 这里需要下载types/nodes 声明
import { resolve } from "path";
import legacyPlugin from "@vitejs/plugin-legacy";
import vueSetupExtend from "vite-plugin-vue-setup-extend";

import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default defineConfig({
  // 开启热更新
  server: {
    open: true,
    port: 8086,
    proxy: {
      '/khnetfix': {
        target: 'https://400dev.konka.com',
        secure: true, //请求是否为https
        changeOrigin: true, //是否跨域
        // rewrite: (path) => {
        //   return path.replace(/\/khnetfix/, '')
        // }
      },
      '/as-web': {
        target: 'https://www.4008800016.com',
        secure: true, //请求是否为https
        changeOrigin: true, //是否跨域
      },
      '/KKCenterUpload': {
        target: 'https://www.4008800016.com',
        secure: true, //请求是否为https
        changeOrigin: true, //是否跨域
      }
      
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    vueSetupExtend(),
    legacyPlugin({
      targets: ["chrome 52"], // 需要兼容的目标列表，可以设置多个
      additionalLegacyPolyfills: ["regenerator-runtime/runtime"], // 面向IE11时需要此插件
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false, // css in js
        }),
      ],
    }),
  ],
  resolve: {
    // 配置别名
    alias: [
        { find: "@", replacement: resolve(__dirname, "src") },
        { find: "@config", replacement: resolve(__dirname, "src/config") },
        { find: "@api", replacement: resolve(__dirname, "src/api") },
        { find: "@comp", replacement: resolve(__dirname, "src/components") },
        { find: "@direct", replacement: resolve(__dirname, "src/directives") },
        { find: "@store", replacement: resolve(__dirname, "src/store") },
        { find: "@style", replacement: resolve(__dirname, "src/style") },
        { find: "@utils", replacement: resolve(__dirname, "src/utils") },
        { find: "@hooks", replacement: resolve(__dirname, "src/hooks") },
        { find: "@type", replacement: resolve(__dirname, "src/type") },
        { find: "@assets", replacement: resolve(__dirname, "src/assets") },
        { find: "@route", replacement: resolve(__dirname, "src/route") },
        { find: "@view", replacement: resolve(__dirname, "src/view") },
    ],
  },
  build: {
    assetsDir: "assets", // 指定生成静态文件目录
    target: ["chrome52"],
    cssTarget: ["chrome52"],
  },
  experimental: {
    renderBuiltUrl(
      filename: string,
      {
        hostId,
        hostType,
        type,
      }: {
        hostId: string;
        hostType: "js" | "css" | "html";
        type: "public" | "asset";
      }
    ) {
      if (type === "public") {
        return { relative: true };
      } else {
        return "/" + filename;
      }
    },
  }
});
